import { ReqPage, ResPage } from "_common/DataType";
import { IotStation } from "_common/entity";
import { createRequest, RequestMethod } from "_common/request";
import { AxiosInstance } from "axios";
/**
 * 站点管理
 */
export class ApiStation {
  /**
   * @description 请求实例
   * @type {RequestMethod}
   * @memberof ApiDevice
   * */
  request: RequestMethod;
  url: string = "api/iot/station";

  /**
   * @description 构造函数
   * @param config axios 配置
   */
  public constructor(instance: AxiosInstance) {
    // axios 实例化
    this.request = createRequest(instance);
  }

  /** 创建 */
  create(data: any) {
    return this.request.post<boolean>(this.url + "", data);
  }

  /** 更新 */
  update(data: any) {
    return this.request.put<boolean>(this.url + "", data);
  }

  /** 删除 */
  delete(id: number) {
    return this.request.delete<boolean>(this.url + "/" + id);
  }

  /** 获取设备列表 */
  getList() {
    return this.request.get<IotStation[]>(this.url + "/get-list");
  }

  /**
   * 获取分页列表
   * @param params
   * @returns
   */
  getPage(params: ReqPage) {
    return this.request.get<ResPage<IotStation>>(
      this.url + "/get-page",
      params
    );
  }
}
